<?php  
//define('APPID', 'wxa4e7830fd');
//define('APPSECRET','f013408d50e0c8d');
 $access_token = "xDx0pD_ZvXkHM3oeu5oGjDt1_9HxlA-9g0vtR6MZ-v4r7MpvZYC4ee4OxN97Lr4irkPKE94tzBUhpZG_OvqAC3D3XaWJIGIn0eeIZnfaofO1C3LNzGphd_rEv3pIimsW9lO-4FOw6D44T3sNsQ5yXQ";
  
 //临时
$qrcode = '{"expire_seconds": 1800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": 10000}}}';
//永久
 $qrcode = '{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": 1000}}}';
 
 $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=$access_token";
 $result = https_request($url,$qrcode);
 $jsoninfo = json_decode($result, true);
 $ticket = $jsoninfo["ticket"];
 
 function https_request($url, $data = null)
 {
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
     if (!empty($data)){
         curl_setopt($curl, CURLOPT_POST, 1);
         curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
     curl_close($curl);
     return$output;
 }

function png($text, $outfile=false, $level=QR_ECLEVEL_L, $size=3, $margin=4, $saveandprint=false)    
{   
    $enc = QRencode::factory($level, $size, $margin);   
    return $enc->encodePNG($text, $outfile, $saveandprint=false);   
}

?>
